{- This file is part of funbot.
 -
 - Written in 2017 by fr33domlover <fr33domlover@riseup.net>.
 -
 - ♡ Copying is an act of love. Please copy, reuse and share.
 -
 - The author(s) have dedicated all copyright and related and neighboring
 - rights to this software to the public domain worldwide. This software is
 - distributed without any warranty.
 -
 - You should have received a copy of the CC0 Public Domain Dedication along
 - with this software. If not, see
 - <http://creativecommons.org/publicdomain/zero/1.0/>.
 -}

{-# LANGUAGE OverloadedStrings #-}

module FunBot.Settings.Sections.Access
    ( isAngel
    , isDemon
    , addDemon
    , removeDemon
    , ignoreDemons
    )
where

import Control.Monad (unless)
import Data.Settings.Types
import Network.IRC.Fun.Types.Base (Nickname)

import qualified Data.HashSet as S

import FunBot.Settings.Persist
import FunBot.Types

isAngel :: Nickname -> BotSession Bool
isAngel nick = S.member nick . stAngels <$> getSettings

isDemon :: Nickname -> BotSession Bool
isDemon nick = S.member nick . stDemons <$> getSettings

addDemon :: Nickname -> BotSession ()
addDemon nick = do
    modifySettings $ \ s -> s { stDemons = S.insert nick $ stDemons s }
    saveBotSettings

removeDemon :: Nickname -> BotSession ()
removeDemon nick = do
    modifySettings $ \ s -> s { stDemons = S.delete nick $ stDemons s }
    saveBotSettings

ignoreDemons :: Respond -> Respond
ignoreDemons resp mchan nick params send = do
    d <- isDemon nick
    unless d $ resp mchan nick params send
